<!--个性化设置-->
<template>
  <div class="all bg1">
    <template v-for="(item, index) in lists">
      <div class="cell bt1" v-bind:key="index" @click="cellClick(item)">
        <text class="font30 text2 all">{{item.title}}</text>
        <text class="font26 text3">{{item.text}}</text>
        <LImage class="img-arrow" :src="Config.img('jiantou_hui.png')"></LImage>      
      </div>
      <div class="line line1" v-bind:key="'line'+index"></div>
    </template>
  </div>
</template>

<style src="@/_css/style.css" ></style>
<style scoped>
.cell {
  flex-direction: row;
  align-items: center;
  height:118px;

  padding-left: 40px;
  padding-right: 40px;
}
.line{
  height: 1px;
  margin-left: 40px;
}
.img-arrow {
  width: 16px;
  height: 26px;
  margin-left: 20px;
}

</style>

<script>

import jnavigator from "@/_js/navigator";
import jmodal from "@/_js/modal";
import jconfig from "@/_js/config";

const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T("设置"));

export default {
  
  data() {
    return {
      T:T,
      Config:jconfig,
      languages:{"zh":"中文",
                 "tc":"繁体",
                 "en":"English",
                 "ja":"日本語",
                 "ko":"한국어",
                 
                 "中文":"zh",
                 "繁体":"tc",
                 "English":"en",
                 "日本語":"ja",
                 "한국어":"ko"},
      lists:[],
    };
  },

  created(){
    
    var unit = {'title':T('计价单位'),'text':'', 'tag':'0'};
    var color = {'title':T('涨跌颜色'),'text':'', 'tag':'1'};
    var language = {'title':T('语言'), 'text':'', 'tag':'2'};
    var sets = {'title':T('更多设置'), 'text':'', 'tag':'3'}

    weexFunction.getConfig("current_bz",(value)=>{
      unit.text = (value == "USD") ? "USD" : "CNY";
    });

    weexFunction.getConfig("green_rose_red",(value)=>{
      color.text = (value ==  "NO") ? T("绿涨红跌") : T("红涨绿跌");
    });

    weexFunction.getConfig("language",(value)=>{
      language.text = this.languages[value];
    });

    this.lists = [unit, color, language, sets];
  },

  methods: {

    /**************** 点击 */
    //列表点击
    cellClick(item) {

      //计价单位
      if (item.tag == '0') {

        var array = ["CNY", "USD"];
        jmodal.actionSheet(array, item.text, (value)=>{
          weexFunction.setConfig("current_bz", value);
          item.text = value;
          jnavigator.back();
        });
        return;
      }

      //涨跌颜色
      if (item.tag == '1') {
        
        var array = [T("红涨绿跌"),T("绿涨红跌")];
        jmodal.actionSheet(array, item.text,(value)=>{

          var text = (value == T("绿涨红跌")) ? "NO" : "YES";
          weexFunction.setConfig("green_rose_red", text);
          item.text = value;
          jnavigator.back();
        });
        return;
      }

      //语言
      if (item.tag == '2') {
        
        var array = ["中文", "繁体", "English", "日本語", "한국어"];
        jmodal.actionSheet(array, item.text, (value)=>{
          
          value = this.languages[value];
          weexFunction.setConfig("language", value);
          item.text = value;
          jnavigator.back();
        });
        return;
      }

      
      //更多设置
      if (item.tag == '3' && jconfig.forceLogin()) {
        jnavigator.open('', 'mine/Sets');
      }
    },
  }
};
</script>
